- content_for :title_header do
  %h1
    = t("layouts.admin.admin")
    = "-"
    = t("admin.communities.conversations.conversations")

= render :partial => "admin/left_hand_navigation", :locals => { :links => admin_links_for(service.community) }

.left-navi-section
  %h2= t("admin.communities.conversations.conversations", community_name: service.community.name(I18n.locale))

  = form_tag '', :method => :get do
    .row
      .col-6
        = text_field_tag :q, params[:q], placeholder: t('admin.communities.conversations.search_by_keyword')
      .col-6
        = submit_tag t("admin.communities.conversations.search"), class: 'button search-button'
        = link_to    t("admin.communities.conversations.reset_search"), admin_community_conversations_path(service.community.id)

  %span#admin_transactions_count
    = page_entries_info(service.conversations, :model => "Conversation")
    - if service.filter?
      = ' '
      = t("admin.communities.conversations.for_keyword", keyword: params[:q]).html_safe

  %table#admin_transactions
    %thead
      %tr
        %th=t("admin.communities.conversations.headers.started_from")
        %th=t("admin.communities.conversations.headers.status")
        %th=render partial: "layouts/sort_link", locals: { column: "started", direction: sort_link_direction("started"), title: t("admin.communities.conversations.headers.started") }
        %th=render partial: "layouts/sort_link", locals: { column: "last_activity", direction: sort_link_direction("last_activity"), title: t("admin.communities.conversations.headers.last_activity") }
        %th=t("admin.communities.conversations.headers.initiated_by")
        %th=t("admin.communities.conversations.headers.other_party")

    %tbody
      - service.conversations.each do |conversation|
        - starter = conversation.starter
        - starter_name = PersonViewUtils.person_display_name_for_type(starter, 'first_name_with_initial')
        - recipient = conversation.recipient
        - recipient_name = PersonViewUtils.person_display_name_for_type(recipient, 'first_name_with_initial')
        %tr
          %td
            - listing = conversation.listing
            - if listing
              - listing_title = listing.title || t("admin.communities.conversations.not_available")
              = link_to_unless listing.deleted, listing_title, listing_path(listing.id)
            - elsif recipient
              = link_to t("admin.communities.conversations.profile", author: recipient_name), person_path(recipient.username)
          %td
            = link_to t("admin.communities.transactions.status.conversation"), admin_community_conversation_path(@current_community.id, conversation.id)
          %td=l(conversation.created_at, format: :short_date)
          %td=l(conversation.last_message_at, format: :short_date)
          %td
            - if starter
              = link_to starter_name, person_path(starter.username)
          %td
            - if recipient
              = link_to recipient_name, person_path(recipient.username)
  .row
    .col-12
      = will_paginate service.conversations
